﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using AjaxPro;

namespace EnvironmentManagerSystem.SearchQuery
{
    public partial class SDSTabone : System.Web.UI.Page
    {
        public Boolean isAdmin = false;
        //窗体加载事件
        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(EnvironmentManagerSystem.HuanJing.HuanJing_Tabone));
            //是否首次加载
            if (StfInfo.ReSession()) return; if (!IsPostBack)
            {
                clear();
                DataBing();
                DataBingP();
            }
        }

        public void clear()
        {
            try
            {
                for (int i = 0; i < this.Form.Controls.Count; i++)
                {
                    if (this.Form.Controls[i] is TextBox) (this.Form.Controls[i] as TextBox).Text = "";
                    else if (this.Form.Controls[i] is Label) (this.Form.Controls[i] as Label).Text = "";
                }
            }
            catch { }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            check();
        }

        /// <summary>
        /// 权限验证
        /// </summary>
        public void check()
        {
            try
            {
                for (int i = 0; i < this.Form.Controls.Count; i++)
                {
                    if (this.Form.Controls[i] is TextBox)
                    {
                        (this.Form.Controls[i] as TextBox).ReadOnly = true;
                    }
                }
            }
            catch { }
        }

        /// <summary>
        /// 进行数据绑定
        /// </summary>
        public void DataBing()
        {
            try
            {
                Hashtable list = EnvironmentManagerSystem.BLL.HuanJing.GetHuanJing(Session["pjName"] != null ? Session["pjName"].ToString() : "");
                if (list != null && list.Count > 0)
                {
                    foreach (DictionaryEntry de in list)
                    {
                        if (this.frm.FindControl(de.Key.ToString()) != null && !de.ToString().Equals("huanjingmingantexing"))
                        {
                            ((TextBox)this.frm.FindControl(de.Key.ToString())).Text = de.Value.ToString();
                        }
                        else if (de.Key.ToString().Equals("huanjingmingantexing"))
                        {
                            String[] sid = de.Value.ToString().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string s in sid)
                            {
                                ((CheckBox)this.frm.FindControl(s)).Checked = true;
                            }
                        }
                    }
                }
            }
            catch
            {
                Jscript.Alert("数据异常", this.Page);
            }
        }

        /// <summary>
        /// 编辑数据库
        /// </summary>
        [AjaxPro.AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
        public void EditTable(string CName, string CValue)
        {
            try
            {
                if (Session["pjName"] != null)
                {
                    EnvironmentManagerSystem.BLL.HuanJing.EditTable(CName, CValue, Session["pjName"] != null ? Session["pjName"].ToString() : "");
                }
            }
            catch { }
        }

        /// <summary>
        /// 进行项目数据绑定
        /// </summary>
        public void DataBingP()
        {
            try
            {
                Hashtable list = EnvironmentManagerSystem.BLL.HuanJing.GetConstructionunit(Session["pjName"] != null ? Session["pjName"].ToString() : "");
                if (list != null && list.Count > 0)
                {
                    #region 建设项目基本信息
                    foreach (DictionaryEntry de in list)
                    {
                        if (this.frm.FindControl(de.Key.ToString()) != null)
                        {
                            ((Label)this.frm.FindControl(de.Key.ToString())).Text = de.Value.ToString();
                        }
                    }

                    #endregion

                    #region 建设单位基本信息
                    Hashtable listTwo = EnvironmentManagerSystem.BLL.HuanJing.GetConstructionunitTwo(list["tbs001_developprojectbasicinfo_js"].ToString());
                    if (listTwo != null)
                    {
                        foreach (DictionaryEntry de in listTwo)
                        {
                            if (this.frm.FindControl(de.Key.ToString()) != null)
                            {
                                ((Label)this.frm.FindControl(de.Key.ToString())).Text = de.Value.ToString();
                            }
                        }
                    }
                    #endregion

                    #region 环评单位信息
                    Hashtable listThree = EnvironmentManagerSystem.BLL.HuanJing.GetConstructionunitThree(list["tbs001_developprojectbasicinfo_hp"].ToString());
                    if (listThree != null)
                    {
                        foreach (DictionaryEntry de in listThree)
                        {
                            if (this.frm.FindControl(de.Key.ToString()) != null)
                            {
                                ((Label)this.frm.FindControl(de.Key.ToString())).Text = de.Value.ToString();
                            }
                        }
                    }
                    #endregion

                    #region
                    if (list["tbs001_developprojectbasicinfo_DevelopState"].ToString().Equals("新建"))
                    {
                        r1.Checked = true;
                        r2.Checked = false;
                        r3.Checked = false;
                        r2.Enabled = false;
                        r3.Enabled = false;
                    }
                    else if (list["tbs001_developprojectbasicinfo_DevelopState"].ToString().Equals("改扩建"))
                    {
                        r2.Checked = true;
                        r1.Checked = false;
                        r3.Checked = false;
                        r1.Enabled = false;
                        r3.Enabled = false;
                    }
                    else
                    {
                        r3.Checked = true;
                        r1.Checked = false;
                        r2.Checked = false;
                        r1.Enabled = false;
                        r2.Enabled = false;
                    }
                    #endregion

                    #region
                    if (list["tbs001_developprojectbasicinfo_Report"].ToString().Equals("报告书"))
                    {
                        r4.Checked = true;
                        r5.Checked = false;
                        r6.Checked = false;
                        r5.Enabled = false;
                        r6.Enabled = false;
                    }
                    else if (list["tbs001_developprojectbasicinfo_Report"].ToString().Equals("报告表"))
                    {
                        r5.Checked = true;
                        r4.Checked = false;
                        r6.Checked = false;
                        r4.Enabled = false;
                        r6.Enabled = false;
                    }
                    else
                    {
                        r6.Checked = true;
                        r4.Checked = false;
                        r5.Checked = false;
                        r4.Enabled = false;
                        r5.Enabled = false;
                    }
                    #endregion
                }
            }
            catch
            {
                Jscript.Alert("数据异常", this.Page);
            }
        }

    }
}
